package ningbo.file;

import java.io.*;
import java.util.Random;


/**
 * @Author 宁铂
 * @Date 2021/7/27 8:45
 * @Version 1.0
 */
public class TestOut {
    /** 本类用于测试字节输出流 */
    public static void main(String[] args) {
        method1(); /** 普通方法 */
        method2(); /** 高效方法 */
    }

    private static void method1() {
        OutputStream out = null;
        try {
            out = new FileOutputStream("F:\\TestFile\\1.txt",true);
            Random random = new Random(47);
            for (int i = 1; i<= 100 ; i++){

               out.write(random.nextInt(100));

            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    private static void method2() {
        OutputStream out = null;
        try {
            out = new BufferedOutputStream(new FileOutputStream("F:\\TestFile\\1.txt",true));
            Random random = new Random(47);
            for (int i = 1; i<= 100 ; i++){

                out.write(random.nextInt(100));

            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
